import * as vscode from 'vscode';
import { StatusBarManager } from './main/wordcount/StatusBarManager';
import { BookManager } from './main/book/BookManager';

let manager: StatusBarManager;

export function activate(context: vscode.ExtensionContext) {
	const bookManager = new BookManager();
	const createProject = bookManager.newProject();

	manager = new StatusBarManager();
	const disposables = [
		createProject,
		vscode.window.onDidChangeActiveTextEditor(e => manager.refresh(e)),
		vscode.workspace.onDidChangeTextDocument(() =>
			manager.refresh(vscode.window.activeTextEditor)
		),
		manager
	];
	context.subscriptions.push(...disposables);
	bookManager.isBook().then(ok => {
		vscode.commands.executeCommand('setContext', 'greatwriter:bookLoaded', ok);
		manager.showWordCounter(vscode.window.activeTextEditor);
	}
	);
}

export function deactivate() {
	manager?.dispose();
}
